package com.mht.book.operation.impl;

import com.mht.book.entity.book.Book;
import com.mht.book.entity.book.BookList;
import com.mht.book.operation.Operations;

import java.util.Arrays;
import java.util.Iterator;
import java.util.Objects;
import java.util.Scanner;

/**
 * @author wangfusheng
 * @version 1.0.0
 * @ClassName FindOperation.java
 * @Description TODO
 * @createTime 2022/12/312:50
 */
public class FindOperation implements Operations {
    @Override
    public void work(BookList bookList) {
        System.out.println("查找图书！");
        System.out.println("请输入你要查找的图书名称：");
        Scanner sc = new Scanner(System.in);
        String name = sc.nextLine();
//        Arrays.stream(bookList.getBooks()).iterator()
//        for (Book book:bookList.getBooks()) {
//            String bookName = book.getName();
//            if(bookName.equalsIgnoreCase(name)){
//                System.out.println("恭喜你，我们找到这本书了，详细信息如下：");
//                System.out.println(bookList.getBooks()[i]);
//                System.out.println();
//                return;
//            }
//        }
        for (int i = 0; i < bookList.getUsedSize(); i++) {
            String bookName = bookList.getBooks()[i].getName();
            if(Objects.equals(name,bookName)){
                System.out.println("恭喜你，我们找到这本书了，详细信息如下：");
                System.out.println(bookList.getBooks()[i]);
                System.out.println();
                return;
            }
        }
        System.out.println("对不起，目前没有您查询的这本书！");
        System.out.println();
    }

//测试方法是否正确
//    public static void main(String[] args) {
//        FindOperation find = new FindOperation();
//        find.work(new BookList());
//    }
}
